Administrator Guide 2017
Generate sequential numbers
Before you start
  1. Is your number to be sequential just on the device? A sequential number created as an Item Type - Calculated Value will be stored on the device and the sequence will be unique to forms filled in on that device.  This means that Device A will generate a sequence of numbers (such as 1001, 1002, 1003) and Device B will also generate the same sequence (ie 1001, 1002, 1003).
  2. Is your number to be sequential across the whole system? A sequential number created as a Template Action - Set a value for an item within the document will be stored on the server (ie is system-wide) and the sequence will cover every form filled in from that template.  This means that (using the above example) forms completed on Device A might generate numbers 1001, 1003 and 1005 while those completed on Device B might generate numbers 1002, 1004 and 1006. 
  3. Server-side numbers can also be set within the job definition.
  4. See our FAQ discussion - Should I create a unique number on the device or on the server?
Why would I use a sequential number?
Common uses include
  1. Sales order numbers - example for creating a system-wide order number
  2. Invoice numbers
  3. Job references
  4. Jobsheet
Overview
  1. Step 1. Create a field for the sequential number within your template.
  2. Step 2. Set up an action to update your sequential number (server-side only)
  3. Step 3. Enter a variable to construct a sequential number.
  4. Example 1. Sales Order Number
Step 1. Create a field for the sequential number within your template
  1. This can be any appropriate Item type for server-sequential numbers but must be a calculated value Item type for device-sequential numbers. For server-sequential numbers, select any appropriate numerical or text Item Type. For device-sequential numbers, select Calculated Value (5th down on the right).

Step 2. Set up an action to update your sequential number (server-side only)
  1. A template action needs to be set up for an appropriate report status.
  2. Click 'Add Action' at the appropriate report status of the template's lifecycle. This is likely to be 'When a report is received from a device (Incomplete or complete)' for creating a job number on an ad-hoc job (ie triggered onsite rather than from the office) but can be on any available action.

  3. Select 'Set a value for an item within the document' (4th down in the middle).

  4. Enter a meaningful description and the unique name applied to the template item in Step 1. 'Value to set' is where you will set up your sequential number (see Step 4). 'Conditions' and 'Post-action processing' tabs are not necessary for this task - see Template Action - Set a value for an item within the document if you wish investigate further.

Step 3. Enter a variable to construct a sequential number.
  1. The format $seq:[sequence name]:[starting number]:[increment] is used in a Calculated Field (for a device-side number) or in a Template Action (for a server-side number).
  2. This example tells magic5 to “use the sequence of numbers that we’re calling ‘DeviceSeqNo', start at 1000 and add on 1 on every time”.

  3. The sequence name is used to allow independent sequences of numbers to exist, such as Order numbers, PO numbers, within a single template.
  4. On the device the user will be asked to confirm that this is the first in a sequence when a sequence is started - this prevents a sequence from accidentally starting from scratch and thereby re-using previously allocated numbers.
  5. The sequence number on a device calculation is local to that device, so may be duplicated across devices - ie the number 10002 might occur several times. If this is a problem you may wish to use something like a username to give a unique value:

    $user-$seq:Order:1000:1

    which would result in, for instance, Fred-1000, Fred-1001 on one device and Bob-1000, Bob-1001 on another.

  6. In a server-based sequence the values will be unique because they are stored and allocated centrally.  Usernames, and other report processing variables can be used, but the syntax is slightly different (eg %USER%-%$seq:sheetno:1000:1% to display Bob-1001 as above).

    A sequence name can be shared between forms.

  7. Update mode

    Update mode determines how magic5 will behave when updating the attribute.  The drop-down box contains the following options:

    • Overwrite existing value – takes the value entered above and replaces the existing value.  This is useful for recording date of most recent visit.
    • Append to existing valueadds the new value onto whatever was there before.  A full history of visit dates might be held in a string of data.
    • Append to existing value with date/time heading – as above, the new value is added to the string of existing data but with the current date/time as well
    • Create value only, don't overwrite – will never overwrite/update so it will only be created once as a new value.  This is useful for recording the date of a first visit or assigning a job number to a job that may take some time to complete.
Example 1. Sales Order Number
  1. Follow Step 1 until you see the 'Add Item' menu.
  2. Select a Text item type from the top left of the menu.

  3. Enter something meaningful under Question, such as 'Order Number', and make sure that the Mandatory box is unticked. The other fields are irrelevant as the software will fill in the data.

  4. In the Advanced tab of the Text item enter a Unique name that reflects what the Text Item is to be used for, such as 'autogenOrderNo'.  Make a note of this for later and save

  5. In the template screen, scroll to 'Actions to take' (this may be above or below the documents, pages, etc) and find the status 'When a report is received from the device (Incomplete or Complete)'. Click on the 'Add Action ...' button.

  6. Select 'Set a value for an item within the document' from the middle of the middle column in the Add Actions menu.

  7. Enter a meaningul description and the unique name of the Text item created above (we called it "autogenOrderNo" but you will have made a note of the name you used).  Enter "$seq:Order:10000:1" in the Value to set prompt and select 'Create value only, don't overwrite' in the Update mode list (see Update mode for alternatives). Click Save and your Order Number is ready to use.

See Also